// pages/counselorshaixuan/counselorshaixuan.js
Page({
  method(){
    console.log(1)
  },
  onClose(){
    this.setData({
      show:false
    })
  },
  popupShow(){
    this.setData({
      show:true
    })
  },
  onFinish(e){
    // console.log(e)
    const diqu = e.detail.selectedOptions
    this.setData({
      vanCellTitle:''
    })
    for(const item of diqu){
      console.log(item.text)
      this.setData({
        vanCellTitle:this.data.vanCellTitle + item.text
      })
    }
  },
  toogleCheckbox1item(e){
    const id = e.currentTarget.dataset.id;
    for(let i = 0;i < this.data.checkbox1.length;i++){
      if(this.data.checkbox1Result.length < 3){
        if(this.data.checkbox1[i].id === id){
          this.data.checkbox1[i].active = !this.data.checkbox1[i].active
        }
      }else if(this.data.checkbox1Result.length === 3){
        if(this.data.checkbox1[i].id === id && this.data.checkbox1[i].active === true){
          this.data.checkbox1[i].active = !this.data.checkbox1[i].active
        }
      }  
    }
    const result =[]
    for(let i = 0;i < this.data.checkbox1.length;i++){
      if(this.data.checkbox1[i].active === true){
        result.push(this.data.checkbox1[i].name)
      }
    }
    this.data.checkbox1Result = [...result]
    console.log(this.data.checkbox1Result)
    this.setData({
      checkbox1:this.data.checkbox1
    })
  },
  onClose2(){
    this.setData({
      show2:false
    })
  },
  popupShow2(){
    this.setData({
      show2:true
    })
  },
  onFinish2(e){
    // console.log(e)
    const level = e.detail.selectedOptions
    this.setData({
      vanCellTitle2:''
    })
    for(const item of level){
      // console.log(item.text)
      this.setData({
        vanCellTitle2:this.data.vanCellTitle2 + item.text
      })
    }
  },
  toogleCheckbox2item(e){
    const id = e.currentTarget.dataset.id;
    for(let i = 0;i < this.data.checkbox2.length;i++){
      if(this.data.checkbox2[i].id === id){
        if(this.data.checkbox2[i].active === false){
          this.data.checkbox2[i].active = true
        }
      }else{
        if(this.data.checkbox2[i].active === true){
          this.data.checkbox2[i].active = false
        }
      }
    }
    this.setData({
      checkbox2:this.data.checkbox2
    })
  },
  toogleCheckbox3item(e){
    const id = e.currentTarget.dataset.id;
    for(let i = 0;i < this.data.checkbox3.length;i++){
      if(this.data.checkbox3[i].id === id){
         if(this.data.checkbox3[i].active === false){
          this.data.checkbox3[i].active = true
         }
      }else{
        if(this.data.checkbox3[i].active === true){
          this.data.checkbox3[i].active = false
        }
      }
    }
    this.setData({
      checkbox3:this.data.checkbox3
    })
  },
  tiaoZhuan(){
    wx.navigateTo({
      url: '/pages/shaixuanresult/shaixuanresult',
    })
  },
  onClickLeft(){
    wx.navigateBack({
      delta: 1 
    })
  },
  data: {
    show:false,
    options:[
      {
        text: '河南省',
        value: '330000',
        children: [{ text: '郑州市', value: '330100' },{ text: '开封市', value: '330200' },{ text: '洛阳市', value: '330300' }],
      },
      {
        text: '江苏省',
        value: '320000',
        children: [{ text: '南京市', value: '320100' }],
      },
    ],
    vanCellTitle:'请选择',
    //所有的擅长标签
    checkbox1:[
      {
        id:1,
        name:'全部',
        active:true
      },
      {
        id:2,
        name:'个人成长',
        active:false
      },
      {
        id:3,
        name:'婚姻家庭',
        active:false
      },
      {
        id:4,
        name:'亲子教育',
        active:false
      },
      {
        id:5,
        name:'恋爱关系',
        active:false
      },
      {
        id:6,
        name:'职场心理',
        active:false
      },
      {
        id:7,
        name:'两性心理',
        active:false
      },
      {
        id:8,
        name:'抑郁梳理',
        active:false
      },
      {
        id:9,
        name:'情绪管理',
        active:false
      },
      {
        id:10,
        name:'人际关系',
        active:false
      },
      {
        id:11,
        name:'心理健康',
        active:false
      },
      {
        id:12,
        name:'婆媳矛盾',
        active:false
      },
    ],
    //保存checkbox1中被选择的标签
    checkbox1Result:[],
    show2:false,
    vanCellTitle2:'请选择',
    options2:[
      {
        text: '国家一级咨询师',
        value: '440000',
      },
      {
        text: '国家二级咨询师',
        value: '430000',
      },
      {
        text: '国家三级咨询师',
        value: '420000',
      }
    ],
    checkbox2:[
      {
        id:1,
        name:'男',
        active:true
      },
      {
        id:2,
        name:'女',
        active:false
      },
      {
        id:3,
        name:'不限',
        active:false
      },
    ],
    checkbox2Resutl:[],
    checkbox3:[
      {
        id:1,
        name:'全部方式',
        active:true
      },
      {
        id:2,
        name:'视频咨询',
        active:false
      },
      {
        id:3,
        name:'语音咨询',
        active:false
      },
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})